package com.cxyd.modules.job.task.wmsTask;

import com.cxyd.modules.wcs.service.ReceiveTaskService;
import com.cxyd.modules.wcs.dto.ReceiveTaskDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Component("analyze-task")
@Slf4j
public class AnalyzeTask {
    @Resource
    private ReceiveTaskService receiveTaskService;
    //创建锁，防止并发情况出现
    private Lock lock = new ReentrantLock();

    public void scanTask() {
        lock.lock();
        try {
            //扫码是否存在待解析的指令[wcs_receive_task]
            ReceiveTaskDTO record = receiveTaskService.getReceiveTask();
            if (record == null) {
//                log.info("no receive-task to analyze...");
                return;
            }
            //调用解析过程(不再使用存储过程)
            receiveTaskService.analyzeHandler(record);
        } catch (Exception e) {
            log.error("搬送指令解析异常，causeBy:{}", e.getMessage());
        } finally {
            lock.unlock();//释放锁
        }
    }
}
